package com.springboot.demo.mapper;

import com.springboot.demo.entity.BorrowMsg;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface BorrowManageMapper {
    @Select("select * from borrow where state='applying'")
    List<BorrowMsg> getBorrowingbook();

    @Update("update borrow set is_successful ='yes',state='borrowing' where phone=#{phone} and ID=#{bookid} and start_time=#{starttime}")
    void setSuccess(String phone,long bookid,String starttime);

    @Update("update borrow set is_successful ='no',state='refused' where phone=#{phone} and ID=#{bookid} and start_time=#{starttime}")
    void setFail(String phone,long bookid,String starttime);

    @Update("update book set situation='borrowed' where ID=#{bookid}")
    void changebooksuc(long bookid);

    @Update("update book set situation='not borrow' where ID=#{bookid}")
    void changebookfail(long bookid);

    @Update("update reader set number=number-1 where phone=#{phone}")
    void readernumminus1(String phone);

    @Select("select * from borrow where phone=#{phone} and state='borrowing' limit #{currIndex},#{pageSize}")
    List<BorrowMsg> selectByPageNumAndPageSize(@Param("currIndex")int currIndex, @Param("pageSize")int pageSize, @Param("phone")String phone);

    @Select("select count(*) from borrow where phone=#{phone} and state='borrowing'")
    int selectAllRecordCount(@Param("phone") String phone);

}
